//https://leetcode.cn/problems/maximum-depth-of-binary-tree/
//二叉树的最大路径
class Solution {
public:
    int maxDepth(TreeNode* root) {
        if(root==nullptr) return 0;
        return dfs(root);
    }
    int dfs(TreeNode* root){
        if(root==nullptr) return 0;
        int left=dfs(root->left);
        int right=dfs(root->right);
        return std::max(left,right)+1;
    }
};
//二叉树的最小路径
class Solution {
public:
    int min_d=INT_MAX;
    void dfs(TreeNode* root,int height){
        if(root==nullptr) return;
        if(root->left==nullptr&&root->right==nullptr){
            height=height+1;
            min_d=std::min(min_d,height);
            return;
        }
        if(root->left){
            dfs(root->left,height+1);
        }
        if(root->right){
            dfs(root->right,height+1);
        }
    }
    int minDepth(TreeNode* root) {
        if(root==nullptr) return 0;
        dfs(root,0);
        return min_d;
    }
};